//
// AHandleRequest.hh for caziac in /home/renaud_j//work/zia-2013s-barrau_a/api/Http
// 
// Made by johannick renaud
// Login   <renaud_j@epitech.net>
// 
// Started on  Sat Sep  3 16:34:15 2011 johannick renaud
// Last update Fri Sep 16 19:02:57 2011 johannick renaud
//

#ifndef			CAZIAC_HANDLEREQUEST_HH
# define		CAZIAC_HANDLEREQUEST_HH

/**
 *	\file		HandleRequest.hh
 *	\date		Mon Sep  5 2011
 *	\author		RENAUD J.
 *	\version	1.0
 */

#include		<map>

#include		"LineRequest.hh"
#include		"IReader.hh"

namespace		Caziac
{

  namespace		Http
  {

    /**
     *	\class		HandleRequest
     *	\brief		Handle for a Request
     */

    class		HandleRequest
    {

    public:

      typedef		std::multimap<std::string, std::string>	Header;

    private:

      LineRequest		_line;
      Header			_header;
      Tools::IReader *		_reader;

    public:

      /**
       *	\param		reader the Socket reader
       *	\brief		constructor of the HandleRequest
       *
       *	This will set attribue "_reader" for later using
       */

      HandleRequest(Tools::IReader *reader);

      /**
       *	\brief		destructor of the HandleRequest
       */

      virtual ~HandleRequest();

      /**
       *	\brief		this function get the header of the Request
       *	\return		the header
       *
       *	This function return the header parsed by the user with
       *   the consumeHeaderLine method. This member function is for consulting.
       */

      Header const &		getHeader() const;

      /**
       *	\brief		this function get the LineRequest (method url version)
       *	\return		the line request
       *	\warning	call readRequestHeader before to set the LineRequest attributes
       *
       *	This member function is only for consulting values.
       */

      LineRequest const&	getLineRequest() const;

      /**
       *	\brief		this function get the Reader which read the stream
       *	\return		the reader
       */

      Tools::IReader *		getReader();

      /**
       *	\brief		use the reader until it will find an empty string
       *
       *	This function consume the reader like this:
       *
       *	- read the first three world to fill the 3 LineRequest fields: method url version
       *	- call consumeHeaderLine with the line until the line returned by the reader is empty
       *
       *
       */

      void			readRequestHeader();

      /**
       *	\param		a line header like "Content-length : 78"
       *	\brief		[User Implementation]
       *
       *	This function parse a line and add a definition to the header with
       *	the addDescription function. The header is a multimap so when you
       *	call three times addDescription with the sames key but different
       *	definition this will save all the 3 values.
       *
       */

      virtual bool		consumeHeaderLine(std::string const &line);

    protected:

      /**
       *	\brief		add a description to the Header
       */

      void			addDescription(std::string const &key,
					       std::string const &def);


    };

  }
}

#endif
